package SGEngine2

import (
	"github.com/gl"
)

var (
	shareMesh map[string]*Mesh = make(map[string]*Mesh)
)

func ShareMeshAdd(meshKey string, mesh *Mesh) {
	shareMesh[meshKey] = mesh
}
func ShareMeshGet(meshKey string) *Mesh {
	return shareMesh[meshKey]
}

type Mesh struct {
	Bounds *Bounds

	Vertices []float32
	UV       []float32
	Color    []float32

	Vertbuffer  gl.Buffer
	UVbuffer    gl.Buffer
	Colorbuffer gl.Buffer

	MeshType int
}

func (this *Mesh) Destory() {
	if this.Vertices != nil {
		this.Vertbuffer.Unbind(gl.ARRAY_BUFFER)
		this.Vertbuffer.Delete()
	}
	if this.UV != nil {
		this.UVbuffer.Unbind(gl.ARRAY_BUFFER)
		this.UVbuffer.Delete()
	}
	if this.Color != nil {
		this.Colorbuffer.Unbind(gl.ARRAY_BUFFER)
		this.Colorbuffer.Delete()
	}
}
